from django.db import models


# Create your models here.
class Ashop(models.Model):
    name = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    pic = models.ImageField()

    class Meta:
        db_table = "Ashop"


class Bshop(models.Model):
    name = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    pic = models.ImageField()

    class Meta:
        db_table = "Bshop"


class Users(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)

    class Meta:
        db_table = "Users"


class Tea(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)

    class Meta:
        db_table = "tea"


class Stu(models.Model):
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    teacher = models.ForeignKey(Tea, models.CASCADE,null=True, blank=True)

    class Meta:
        db_table = "stu"


# 年级
class Grade(models.Model):
    name = models.CharField(max_length=30)

    class Meta:
        db_table = "grade"


# 课程
class lesson(models.Model):
    name = models.CharField(max_length=20)
    grades = models.ForeignKey(Grade,models.CASCADE,related_name="gra")

    class Meta:
        db_table = "lesson"

class Friend(models.Model):
    name = models.CharField(max_length=50)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)
    niaji = models.ForeignKey(Grade,models.CASCADE)
    class Meta:
        db_table = "firend"


class Move(models.Model):
    name = models.CharField(max_length=50)
    uptime = models.DateField(max_length=100)
    pic = models.ImageField()
    class Meta:
        db_table = "Move"


class PeopleM(models.Model):
    name = models.CharField(max_length=10)
    age = models.IntegerField()
    gender = models.CharField(max_length=10)
    move = models.ForeignKey(Move,on_delete=models.CASCADE,related_name="move")
    class Meta:
        db_table = "PeopleM"

#商品表
class ShoopM(models.Model):
    name = models.CharField(max_length=20,verbose_name="商品")
    price = models.DecimalField(max_digits=5,decimal_places=2,verbose_name="价格")
    tlacknum  = models.IntegerField(verbose_name="评论数量")#评论数量
    pic = models.ImageField(upload_to="pic",verbose_name="图片")
    class Meta:
        db_table = "ShoopM"
        verbose_name = "商品表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name
#用户表
class UserM(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=200)
    class Meta:
        db_table = "UserM"
#评论表
class Tlack(models.Model):
    users = models.ForeignKey(UserM,on_delete=models.CASCADE)
    shoops = models.ForeignKey(ShoopM,on_delete=models.CASCADE)
    txt = models.TextField()
    class Meta:
        db_table = "Tlack"

#领导
class Schooluser(models.Model):
    username = models.CharField(max_length=50)
    password  = models.CharField(max_length=200)
    class Meta:
        db_table = "schooluser"

#校区
class School(models.Model):
    name = models.CharField(max_length=50,verbose_name="校区")
    explain = models.CharField(max_length=200,verbose_name="校区说明")
    class Meta:
        db_table = "school"

#班级
class Classschool(models.Model):
    name  = models.CharField(max_length=50,verbose_name="班级名")
    classexplain = models.CharField(max_length=200,verbose_name="班级说明")
    school = models.ForeignKey(School,on_delete=models.CASCADE,verbose_name="所在校区")
    openclass = models.DateTimeField(verbose_name="开班时间")
    closeclass = models.DateTimeField(verbose_name="结课时间")
    class Meta:
        db_table = "classschool"
#学生
class Studentschool(models.Model):
    name = models.CharField(max_length=50,verbose_name="姓名")
    mobile = models.CharField(max_length=11,verbose_name="手机号")
    schools = models.ForeignKey(School,on_delete=models.CASCADE,verbose_name="关联学校外键")
    xueli = models.CharField(max_length=20,verbose_name="学历")
    classmee = models.ForeignKey(Classschool,on_delete=models.CASCADE,verbose_name="关联班级外键")
    schoolusers = models.ForeignKey(Schooluser,on_delete=models.SET_NULL,null=True,blank=True,verbose_name="关联老师外键")
    class Meta:
        db_table = "studentschool"

class KeHu(models.Model):
    name = models.CharField(max_length=10,unique=True)
    yeiwu = models.CharField(max_length=10)
    area = models.CharField(max_length=10,unique=True)
    lianxiren = models.CharField(max_length=10)
    youzhengbianma = models.CharField(max_length=10,unique=True)
    yeiwuyuan = models.CharField(max_length=30)
    class Meta:
        db_table = "KeHu"

class Jinchu(models.Model):
    gongsiname = models.ForeignKey(KeHu,to_field="name",on_delete=models.CASCADE,related_name="names")
    ditetime = models.CharField(max_length=100,unique=True)
    number = models.IntegerField(default=0,unique=True)
    class Meta:
        db_table ="Jinchu"

class Areas(models.Model):
    diquname = models.ForeignKey(KeHu,to_field="area",on_delete=models.CASCADE,related_name="areaa")
    bianmaname = models.ForeignKey(KeHu,to_field="youzhengbianma",on_delete=models.CASCADE,related_name="ywbm")
    class Meta:
        db_table = 'Areas'
















